'https://api.coze.cn/open_api/v2/chat'
'pat_3uyfvzpqxeQPLWrc3ojpOo0N23zbjcNcMamdX87Jdq86xvXukblmCid0DTjWpAzw' // ⚠️ 正式环境请放到后端

import axios from 'axios'

const COZE_API_URL = 'https://api.coze.cn/open_api/v2/chat'

// ⚠️ 注意：生产环境不要直接写 API Key，建议放后端
const COZE_API_KEY =
  'pat_3uyfvzpqxeQPLWrc3ojpOo0N23zbjcNcMamdX87Jdq86xvXukblmCid0DTjWpAzw'
const AGENT_ID = '7561420672098926638'

export async function sendToAgent(message: string) {
  try {
    const res = await axios.post(
      COZE_API_URL,
      {
        bot_id: AGENT_ID,
        user: 'user-001',
        query: message,
        stream: false
      },
      {
        headers: {
          Authorization: `Bearer ${COZE_API_KEY}`,
          'Content-Type': 'application/json'
        }
      }
    )

    return res.data.messages?.[0]?.content ?? '没有返回结果'
  } catch (err) {
    console.error('Agent请求失败:', err)
    return '请求失败，请稍后再试'
  }
}
